<template>
  <div>
    <el-breadcrumb>
      <el-breadcrumb-item>港口管理查询</el-breadcrumb-item>
    </el-breadcrumb>
    <el-card>
      <el-table :data="portlist" stripe style="width: 100%">>
          <el-table-column
            prop="port_id"
            label="仓库编号"
            width="250">
          </el-table-column>
          <el-table-column
            prop="port_specified"
            label="核定容量"
            width="250">
          </el-table-column>
          <el-table-column
            prop="port_used"
            label="仓库已用容量"
            width="250">
          </el-table-column>
          <el-table-column
            prop="port_surplus"
            label="仓库剩余容量"
            width="250">
          </el-table-column>
          <el-table-column
            label="操作">
            <template slot-scope="scope">
              <el-button type="primary" icon="el-icon-edit" @click="showUpdataDialog(scope.row)" circle></el-button>
              <el-button type="danger" icon="el-icon-delete" @click="showDeleteDialog(scope.row)" circle></el-button>
            </template>
          </el-table-column>
        </el-table>
    </el-card>
    <el-dialog
        :visible.sync="updataDialogVisible"
        width="30%">
        <el-form :model="formvalue" label-width="80px">
          <el-form-item label="仓库编号">
            <el-input v-model="formvalue.port_id" :disabled="true" ></el-input>
          </el-form-item>
          <el-form-item label="核定容量">
            <el-input v-model="formvalue.port_specified"></el-input>
          </el-form-item>
          <el-form-item label="仓库已用容量">
            <el-input v-model="formvalue.port_used"></el-input>
          </el-form-item>
          <el-form-item label="仓库剩余容量">
            <el-input v-model="formvalue.port_surplus"></el-input>
          </el-form-item>
        </el-form>
        <span slot="footer" class="dialog-footer">
          <el-button @click="updataDialogVisible = false">取 消</el-button>
          <el-button type="primary" @click="updataPort">确 定</el-button>
        </span>
     </el-dialog>
     <el-dialog
         :visible.sync="deleteDialogVisible"
         width="30%">
         <el-form :model="formvalue" label-width="80px">
           <el-form-item label="仓库编号">
             <el-input v-model="formvalue.port_id" :disabled="true"></el-input>
           </el-form-item>
           <el-form-item label="核定容量">
             <el-input v-model="formvalue.port_specified" :disabled="true"></el-input>
           </el-form-item>
           <el-form-item label="仓库已用容量">
             <el-input v-model="formvalue.port_used" :disabled="true"></el-input>
           </el-form-item>
           <el-form-item label="仓库剩余容量">
             <el-input v-model="formvalue.port_surplus" :disabled="true"></el-input>
           </el-form-item>
         </el-form>
         <span slot="footer" class="dialog-footer">
           <el-button @click="deleteDialogVisible = false">取 消</el-button>
           <el-button type="primary" @click="dletePort">确 定</el-button>
         </span>
      </el-dialog>
  </div>
</template>

<script>
export default {
  data() {
    return {
      portlist: [],
      updataDialogVisible: false,
      deleteDialogVisible: false,
      formvalue: {}
    }
  },
  created() {
    this.getPortlist()
  },
  methods: {
    async getPortlist() {
      const { data: res } = await this.$http.get('customer')
      this.portlist = res.data.value
    },
    showUpdataDialog(rowvalue) {
      this.updataDialogVisible = true
      this.formvalue = rowvalue
    },
    async updataPort() {
      await this.$http.put('customer', {
        port_id: this.formvalue.port_id,
        port_specified: this.formvalue.port_specified,
        port_used: this.formvalue.port_used,
        port_surplus: this.formvalue.port_surplus
      })
      this.getPortlist()
      this.updataDialogVisible = false
    },
    showDeleteDialog(rowvalue) {
      this.deleteDialogVisible = true
      console.log(rowvalue)
      this.formvalue = rowvalue
    },
    async dletePort() {
      await this.$http.delete('customer?port_id=' + this.formvalue.port_id)
      this.getPortlist()
      this.deleteDialogVisible = false
    }
  }
}
</script>

<style lang="less" scoped>
</style>
